<template>
    <div class="box">
        <div>
            <img style="width: 196px;height: 73px;" src="../../assets/logo.png" />
            <div>
                <span class="title">德仁源僵蚕养殖追溯系统</span>
                <span class="info1">以规范化、规模化生产僵蚕为目的的公司，拥有专用桑园、小蚕共育工厂、僵蚕养殖工厂及僵蚕技术中心。并率先建立了国内第一家拥有动物防疫合格证的规范化规模化僵蚕养殖生产基地。始终坚持以“做道地药材，造济世良药、守护人类健康”为使命。</span>
            </div>
            <img  src="../../assets/img/banner_login.png" style="width: 80%;;margin: 50px 0 59px;" />
            <div class="info2">
                技术支持：<a href="javasc:;">原链科技</a>
            </div>
        </div>
        <div class="login">
            <p class="login-title">账号登录</p>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="0px" class="ms-content">
                <el-form-item prop="username">
                    <div class="form_item">
                        <i class="user"></i>
                        <el-input v-model.trim="ruleForm.username" placeholder="用户名"  />
                    </div>
                </el-form-item>

                <el-form-item prop="password">
                    <div class="form_item">
                        <i class="password"></i>
                        <el-input v-model.trim="ruleForm.password" placeholder="密码" type="password" @keyup.enter.native="submitForm()" />
                    </div>
                </el-form-item>
                <el-form-item prop="num">
                    <div class="form_item">
                        <i class="auth_code"></i>
                        <el-input v-model.trim="ruleForm.num" placeholder="验证码" auto-complete="off" />
                        <div class="login-code" @click="init">
                            <s-identify :identifyCode="identifyCode"></s-identify>
                        </div>
                    </div>
                </el-form-item>
                <el-form-item>
                    <el-button round type="success" @click="submitForm('ruleForm')">登录</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import axios from "axios"
import { logins, goverment_check, user_checkCode } from '@/request/api'
import SIdentify from '../common/authcode'
export default {
    components: { SIdentify },
    data() {
        return {
            isgt: false,
			identifyCodes: 'z645xcvbnml786kjhfgda453sqerty579uiop12347890',
			identifyCode: "",
			code: '',
			ruleForm: {
				username: '',
				password: '',
				num: ''
			},
			rules: {
				username: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
				password: [{ required: true, message: '请输入密码', trigger: 'blur' }],

			},
        };
    },
	created(){
		localStorage.setItem("requestUrl", "http://47.108.220.160:90/jcApi/plant/")
	},
    mounted() {
        this.init()
    },
    methods: {
        init() {
			axios.get("http://47.108.220.160:90/jcApi/plant/user/checkCode").then((res) => {
				this.identifyCode = res.data.data
			})
		},
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
					let data = {
						username: this.ruleForm.username,
						password: this.ruleForm.password,
						checkCode: this.ruleForm.num,
						type: 'fruit'
					}
					axios.post("http://47.108.220.160:90/jcApi/plant/user/logins", data).then(arr => {
						sessionStorage.setItem('userName',this.ruleForm.username)
						sessionStorage.setItem('password',this.ruleForm.password)
						var res = arr.data
						if (res.appMenus && res.appMenus.length > 0) {
							this.$notify({
								title: '提示',
								message: '登录成功',
								type: 'success',
								duration: 1000
							});
							const list = [];
							if (res.userInfo.userType === "GOV") {
								for (let r = 0; r < res.appMenus.length; r++) {
									if (res.appMenus[r].appId === "001") {
										list.push(res.appMenus[r])
									}
								}
								localStorage.setItem("zh_type", "GOV")
								res.appMenus = list
								this.$util.set("userInfo", res);
							} else {
								this.$util.set("userInfo", res);
							}

							localStorage.setItem("loginname", res.userInfo.name)
							localStorage.setItem("headImg", res.userInfo.headImg)
							localStorage.setItem("companyId", res.userInfo.companyId)
							localStorage.setItem("userType", res.userInfo.userType)

							goverment_check(res.userInfo.companyId).then((res) => {
								this.$store.commit("setlogoimg", res.data.logoImg)
								this.$store.commit("setlogozImg", res.data.logozImg)
							})
							console.log(res.appMenus[0].appId)
							if (res.appMenus[0].appId === "001") {
								localStorage.setItem("requestUrl", "http://47.108.220.160:90/jcApi/plant/control/")
                                // http://124.89.83.30:90/||xlsApi
								var r = localStorage.getItem("requestUrl")
							} else if (res.appMenus[0].appId === "002") {
								localStorage.setItem("requestUrl", "http://47.108.220.160:90/jcApi/plant/")
							} else if (res.appMenus[0].appId === "003") {
								localStorage.setItem("requestUrl", "http://47.108.220.160:90/jcApi/plant/breed/")
							} else if (res.appMenus[0].appId === "004") {
								localStorage.setItem("lj", "生产")
								localStorage.setItem("requestUrl", "http://47.108.220.160:90/jcApi/plant/produce/")
							} else if (res.appMenus[0].appId === "007") {
								localStorage.setItem("requestUrl", "http://47.108.220.160:90/jcApi/plant/produce/")
							}
							this.$store.commit("setuserid", res.userInfo.id)
							localStorage.setItem('ms_username', this.ruleForm.username);
							localStorage.setItem('ms_id', res.userInfo.id);
							sessionStorage.setItem('setTabStatus', "sss")
							this.$store.commit('setname', this.ruleForm.username)
							this.$store.commit('settoken', res.token)
							if (res.appMenus[0].appId === "004") {
								localStorage.setItem("lj", "生产")
							} else {
								localStorage.setItem("lj", "1")
							}

							if (res.appMenus[0].configMenus.length > 0) {
								localStorage.setItem("system", "show")
								this.$store.commit("setsystem", res.appMenus[0].configMenus)
							} else {
								localStorage.removeItem("system")
							}

                            if(res.userInfo.userType == 'GOV'){
                                this.$router.push({ path: '/supervisionCenterhome' });
                            }else{
                                this.$router.push({ path: '/home' });
                            }
						} else {
							this.$notify({
								title: '提示',
								message: '没有应用权限,请联系管理员开通',
								type: 'error',
								duration: 1000
							});
						}
					})
                } else {
                    return false;
                }
            });
        },
    }
};
</script>

<style scoped lang="less">
.box {
    display: flex;
    width: 100vw;
    height: 100vh;
    padding:0 190px;
    padding-top: 120px;
    box-sizing: border-box;
    background-image: url(../../assets/img/background.png);
    background-size: 100% 100%;
    overflow: auto;
}
.title {
    display: block;
    font-weight: 600;
    font-size: 38px;
    color: #231f20;
    padding: 48px 0;
}
.info1 {
    font-size: 18px;
    line-height: 44px;
    display: block;
    color: #737373;
}
.info2 {
    font-size: 12px;
    line-height: 28px;
    color: #737373;
}
.login {
    width: 538px;
    min-width: 538px;
    height: 760px;
    font-weight: 600;
    padding-top: 84px;
    padding-left: 56px;
    padding-right: 56px;
    background: #ffffff;
    box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    margin-left: 219px;
    box-sizing: border-box;
}
.login-title {
    font-size: 36px;
    color: #282829;
    padding-bottom: 118px;
}
.form_item {
    display: flex;
    justify-content: center;
    align-items: center;
    i {
        display: block;
        width: 26px;
        height: 26px;
        margin-right: 12px;
    }
    .user {
        background-image: url(../../assets/img/user.png);
    }
    .password {
        background-image: url(../../assets/img/pwd.png);
    }
    .auth_code {
        flex-shrink: 0;
        background-image: url(../../assets/img/auth_code.png);
    }
}
.el-form-item__content button {
    width: 100%;
    height: 56px;
    font-size: 18px;
    color: #fff;
    margin-top: 104px;
    border-radius: 24px;
    background-color: #05b089;
}
.forget_pwd {
    display: flex;
    justify-content: center;
    align-items: center;
}
.el-link {
    font-size: 14px;
    color: #05b089;
}
</style>
